package com.qys.training.listen;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.instance.HazelcastInstanceFactory;
import com.qys.training.cache.HazelcastClientFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import javax.annotation.Resource;

public class StartListener implements ApplicationListener<ContextRefreshedEvent> {
    public static final Logger logger = LoggerFactory.getLogger(StartListener.class);

//    @Resource
//    private HazelcastInstance hazelcastinstance;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
//        IMap<Object, Object> map = hazelcastinstance.getMap("listener");
//        map.put("listener", 1);
        HazelcastInstance hazelcastInstance = new HazelcastClientFactory().hazelcastClient();
        IMap<Object, Object> map = hazelcastInstance.getMap("listener");
        map.put("listener", 1);
        logger.info("openapi项目启动");
    }
}
